package net.csdn.business.discuss.api.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.discuss.api.model.entity.DiscussCategory;
import net.csdn.business.discuss.api.model.query.DiscussCategoryQuery;
import net.csdn.business.discuss.api.model.vo.DiscussCategoryVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 讨论分类Mapper接口
 * 
 * @author Admin Cloud
 * @date 2023-07-15
 */
public interface DiscussCategoryMapper  extends BaseMapper<DiscussCategory>
{

    /**
     * 分页查询讨论分类列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    public List<DiscussCategoryVO> findPageList(Page page, @Param("query") DiscussCategoryQuery query);

    /**
     * 查询讨论分类
     * 
     * @param id 讨论分类主键
     * @return 讨论分类
     */
    @Select("select t1.* FROM discuss_category t1 where t1.object_id=#{id} order by t1.created_date asc")
    public DiscussCategoryVO selectDiscussCategoryById(@Param("id")String id);

    @Select("select t1.* FROM discuss_category t1 where t1.source_id=#{sourceId} and t1.source_type=#{sourceType} order by t1.created_date asc")
    public List<DiscussCategoryVO> getListBySourceId(@Param("sourceId")String sourceId,@Param("sourceType")Integer sourceType);

    @Select("select t1.* FROM discuss_category t1 where t1.section_id=#{sectionId} order by t1.created_date asc")
    public List<DiscussCategoryVO> getListBySectionId(@Param("sectionId")String sectionId);

    /**
     * @Author zhangyl
     * @Description 根据sourceId查询未分组的分类
     * @Date 17:05 2023/7/15
     * @Param
     * @return
     **/
    @Select("select t1.* FROM discuss_category t1 where t1.source_id=#{sourceId} and t1.section_id is null order by t1.created_date asc")
    public List<DiscussCategoryVO> getListNoSection(@Param("sourceId")String sourceId);

    @Select("select t1.* FROM discuss_category t1 where t1.section_id=#{sectionId} order by t1.created_date asc")
    public List<DiscussCategoryVO> getListSectionId(@Param("sectionId")String sectionId);

    /**
     * 查询讨论分类列表
     * 
     * @param query 讨论分类
     * @return 讨论分类集合
     */
    @Select("select t1.* FROM discuss_category t1 where t1.source_id=#{sourceId} order by t1.created_date asc")
    public List<DiscussCategoryVO> selectDiscussCategoryList(@Param("query") DiscussCategoryQuery query);


    @Update("update discuss_category set section_id= null where section_id=#{sectionId}")
    public Integer deleteSection(@Param("sectionId") String sectionId);

    @Select("select count(*) FROM discuss_category t1 where t1.source_id=#{sourceId}")
    public Integer selectDiscussCategoryTotal(@Param("sourceId")String sourceId);
}
